import { reqCartList,reqDeleteCartById } from "@/api";

const state = {
  cartList:[],
};
const mutations = {
  GETCARTLIST(state,cartList){
     state.cartList=cartList
  }
};
const actions = {
    // 获取购物车列表数据
  async getCartList({commit}) {
    let res = await reqCartList();
    if(res.code==200){
      commit("GETCARTLIST",res.data)
    }
  },
  // 删除购物车内某一个产品
  async deleteCartLIstBySkuId({commit},skuId){
    let res=await reqDeleteCartById(skuId)
    if(res.code==200){
      return 'ok'
    }else{
      return Promise.reject(new Error('faile'))
    }
  }
};

const getters = {
  cartList(state){
    return state.cartList[0]||{}
  },
  
};
export default {
  state,
  mutations,
  actions,
  getters,
};
